#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	string s;
	cin >> s;
	vector<int> a(10, 0);
	for (auto e : s)
	{
		int x = e - '0';
		a[x]++;
	}
	string t;
	for (int j = 0; j < 10; j++)
	{
		for (int i = 0; i <= 9; i++)
		{
			if (a[i] && i >= 9 - j)
			{
				t += to_string(i);
				a[i]--;
				break;
			}
		}
	}
	cout << t << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}